#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

void TestStat()
{
    std::string path = "wwwroot";
    path += '/';
    path += "index.html";
    struct stat st;
    if(stat(path.c_str(), &st) == 0)
    {
        std::cout << "Yes" << std::endl;
    }
    else std::cout << "No" << std::endl;
}

void TestEnv()
{
    
    //std::cerr << "METHOD=" << NULL << std::endl;
    //std::cerr << "QUERY_STRING=" << NULL << std::endl;
    //const char* method = getenv("METHOD");
    //std::cerr << "METHOD=" << method << std::endl;
    //const char* str =  getenv("QUERY_STRING");
    //std::cerr << "QUERY_STRING=" << str << std::endl;
    //std::cerr << "..........................................." << std::endl;
}

void TestStringStream()
{
    std::string str = "GET /index.html http/1.1";
    std::stringstream ss(str);
    std::string method;
    std::string url;
    std::string version;
    ss >> method >> url >> version;
    std::cout << "method: " << method << std::endl;
    std::cout << "url: " << url << std::endl;
    std::cout << "version: " << version << std::endl;
}

void TestGoto()
{
    goto End;

    //int case = 100;
End:
    std::cout << "Run ..." << std::endl;
}

void TestTransform()
{
    std::string str = "post";
    std::cout << "Before transform: " << str << std::endl;
    std::transform(str.begin(), str.end(), str.begin(), ::toupper);
    std::cout << "After transform: " << str << std::endl;
}

int main()
{
    //TestTransform();
    //TestEnv();
    //TestStringStream();
    TestTransform();
    return 0;
}
